<cfparam name="Institution_ID" type="integer" default="0" />
<cfparam name="returnView" type="string" default="institutions" />
<cfparam name="passback" type="string" default="" />

<cfscript>
	institutionGateway = new assets.calgrants.com.gateway.InstitutionGateway();
	institution = institutionGateway.get(Institution_ID = Institution_ID);
</cfscript>

<cfif IsNumeric(institution.getInstitution_ID())>
	
	<cfscript>
		base = new assets.calgrants.com.Base();
		passbackQueryString = base.passbackToQueryString(passback);
		storedProcedureGateway = new assets.calgrants.com.gateway.StoredProcedureGateway();
		states = storedProcedureGateway.call("getDistinctStates");
		//countyGateway = new assets.calgrants.com.gateway.CountyGateway();
		//counties = countyGateway.query(Region_ID = IIf(IsUserInRole("Organizer") OR IsUserInRole("Site Contact"), request.authUser.regionID, ""));
	</cfscript>
	
	<script type="text/javascript" language="javascript">
	<!--
	
		<!--- <cfoutput>
			var countyID = #institution.getCounty_ID()#;
			var counties =  new kendo.data.DataSource();
			counties.data(#SerializeJSON(base.QueryToStruct(counties), false)#);
		</cfoutput> --->
		
		validate = function() {
			var errors = "";
			var valid = true;
			//validation logic
			if (!valid) {
				alert(errors);
			}
			return valid;				
		}
		
		$(function() {			
			/*countyDropdown = $("#County_ID").kendoDropDownList({
				dataTextField: "county",
				dataValueField: "county_id",
				dataSource: counties,
				template: 	'<strong>${county}</strong><br>' +
							'${region_id} - ${region} Region'
			}).data("kendoDropDownList");
			countyDropdown.value(countyID);*/
			$("#institutionModal").modal();
			resizeModal("institutionModal");	
		})
	//-->
	</script>
	
	<cfoutput>
	
		<cfform id="institutionForm" name="institutionForm" action="#script_name#" method="post" onsubmit="return validate();">
			<cfinput type="hidden" name="action" value="saveInstitution" />
			<cfinput type="hidden" name="view" value="#returnView#" />
			<cfinput type="hidden" name="Institution_ID" value="#institution.getInstitution_ID()#" />
			<cfif IsDefined("passback")>
				<cfloop index="keyValue" list="#passback#" delimiters=";">
					<cfinput type="hidden" name="#ListFirst(keyValue)#" value="#ListLast(keyValue)#" />
				</cfloop>
			</cfif>
			
			<div id="institutionModal" class="modal modal-fullscreen" data-backdrop="static">
				<div class="modal-header">
					<h3>Institution</h3>
				</div>
				<div class="modal-body">
					<div class="row-fluid">
						<div class="span4">
							<cfif IsUserInRole("Super User") or IsUserInRole("Regional Admin")>
								<div class="clearfix">
									<label for="Status" class="required">Status</label>
									<cfselect name="Status" required="yes" message="Status is required" class="span12">
										<option value="n">Pending Review</option>
										<option value="d"<cfif institution.getDisqualified() eq 1> selected</cfif>>Disqualified</option>
										<option value="a"<cfif institution.getApproved() eq 1> selected</cfif>>Approved</option>
									</cfselect>
								</div>
							<cfelse>
								<div class="text-control clearfix">
									<label>Status</label>
									<input type="hidden" name="Approved" value="#institution.getApproved()#" />
									<input type="hidden" name="Disqualified" value="#institution.getDisqualified()#" />
									<cfif institution.getDisqualified() eq 1>
										Diqualified
									<cfelseif institution.getApproved() eq 1>
										Approved
									<cfelse>
										Pending Review
									</cfif>
								</div>
							</cfif>
							<div class="clearfix">
								<label for="Institution" class="required">Name</label>
								<cfinput type="text" name="Institution" value="#institution.getInstitution()#" required="yes" message="Name is required" maxlength="200" class="span12">
							</div>
							<div class="clearfix">
								<label for="Term_Type" class="required">Term Type</label>
								<cfselect name="Term_Type" required="yes" message="Term Type is required" class="span12">
									<option value="">Select...</option>
									<option value="Semester"<cfif institution.getTerm_Type() eq "semester"> selected</cfif>>Semester</option>
									<option value="Quarter"<cfif institution.getTerm_Type() eq "quarter"> selected</cfif>>Quarter</option>
								</cfselect>
							</div>
							<div class="clearfix">
								<label for="Accredited" class="required">Accredited</label>
								<cfselect name="Accredited" required="yes" message="Accredited is required" class="span12">
									<option value="">Select...</option>
									<option value="1"<cfif institution.getAccredited() eq 1> selected</cfif>>Yes</option>
									<option value="0"<cfif institution.getAccredited() eq 0> selected</cfif>>No</option>
								</cfselect>
							</div>
							<div class="clearfix">
								<label for="Degree_Granting" class="required">Degree Granting</label>
								<cfselect name="Degree_Granting" required="yes" message="Degree Granting is required" class="span12">
									<option value="">Select...</option>
									<option value="1"<cfif institution.getDegree_Granting() eq 1> selected</cfif>>Yes</option>
									<option value="0"<cfif institution.getDegree_Granting() eq 0> selected</cfif>>No</option>
								</cfselect>
							</div>
							<div class="clearfix">
								<label for="Degree_Granting" class="required">Degree Granting</label>
								<cfselect name="Degree_Granting" required="yes" message="Degree Granting is required" class="span12">
									<option value="">Select...</option>
									<option value="1"<cfif institution.getDegree_Granting() eq 1> selected</cfif>>Yes</option>
									<option value="0"<cfif institution.getDegree_Granting() eq 0> selected</cfif>>No</option>
								</cfselect>
							</div>
						</div>
						<div class="span8">
							<div class="tabbable tabs-top">
								<ul class="nav nav-tabs">
									<li class="active"><a href="##FAO" data-toggle="tab">Financial Aid Office Address</a></li>
									<li><a href="##alt" data-toggle="tab">Alternate Payment Address</a></li>
								</ul>
								<div class="tab-content">
									<div class="tab-pane active" id="FAO">
										<div class="row-fluid">
											<div class="span6">
												<div class="row-fluid">
													<div class="span6">
														<label for="FAO_First_Name">First Name</label>
														<cfinput name="FAO_First_Name" type="text" value="#institution.getFAO_First_Name()#" maxlength="50" class="span12" />
													</div>
													<div class="span6">
														<label for="FAO_Last_Name">Last Name</label>
														<cfinput name="FAO_Last_Name" type="text" value="#institution.getFAO_Last_Name()#" maxlength="50" class="span12" />
													</div>
												</div>
												<div class="clearfix">
													<label for="FAO_Title">Title</label>
													<cfinput name="FAO_Title" type="text" value="#institution.getFAO_Title()#" maxlength="100" class="span12" />
												</div>
												<div class="clearfix">
													<label for="FAO_Email">E-mail</label>
													<cfinput name="FAO_Email" type="text" value="#institution.getFAO_Email()#" maxlength="100" class="span12" />
												</div>
												<div class="clearfix">
													<label for="FAO_Phone">Phone</label>
													<cfinput name="FAO_Phone" type="text" value="#institution.getFAO_Phone()#" validate="telephone" message="Phone must be in ######-######-######## format" class="span12" placeholder="######-######-########" />
												</div>
											</div>
											<div class="span6">
												<div class="clearfix">
													<label for="FAO_Address1">Address 1</label>
													<cfinput type="text" name="FAO_Address1" value="#institution.getFAO_Address1()#" required="no" message="Address 1 is required" maxlength="200" class="span12" />
												</div>
												<div class="clearfix">
													<label for="FAO_Address2">Address 2</label>
													<cfinput type="text" name="FAO_Address2" value="#institution.getFAO_Address2()#" required="no" message="Address 2 is required" maxlength="200" class="span12" />
												</div>
												<div class="clearfix">
													<div class="row-fluid">
														<div class="span6">
															<label for="FAO_City">City</label>
															<cfinput type="text" name="FAO_City" value="#institution.getFAO_City()#" required="no" message="City is required" maxlength="100" class="span12">
														</div>
														<div class="span3">
															<label for="FAO_State">State</label>
															<cfselect name="FAO_State" query="states" display="Code" value="Code" selected="#institution.getFAO_State()#" queryPosition="below" class="span12">
																<option value="">Select...</option>
															</cfselect>
														</div>
														<div class="span3">
															<label for="FAO_Zip_Code">Zip Code</label>
															<cfinput type="text" name="FAO_Zip_Code" value="#institution.getFAO_Zip_Code()#" required="no" message="Zip Code is required and must be a valid zip code" validate="zipcode" maxlength="5" class="span12">
														</div>
													</div>
												</div>
											</div>
										</div>
									</div>
									<div class="tab-pane" id="alt">
										<div class="row-fluid">
											<div class="span6">
												<div class="clearfix">
													<div class="row-fluid">
														<div class="span6">
															<label for="Payment_First_Name">First Name</label>
															<cfinput name="Payment_First_Name" type="text" value="#institution.getPayment_First_Name()#" maxlength="50" class="span12" />
														</div>
														<div class="span6">
															<label for="Payment_Last_Name">Last Name</label>
															<cfinput name="Payment_Last_Name" type="text" value="#institution.getPayment_Last_Name()#" maxlength="50" class="span12" />
														</div>
													</div>
												</div>
												<div class="clearfix">
													<label for="Payment_Title">Title</label>
													<cfinput name="Payment_Title" type="text" value="#institution.getPayment_Title()#" maxlength="100" class="span12" />
												</div>
												<div class="clearfix">
													<label for="Payment_Email">E-mail</label>
													<cfinput name="Payment_Email" type="text" value="#institution.getPayment_Email()#" maxlength="100" class="span12" />
												</div>
												<div class="clearfix">
													<label for="Payment_Phone">Phone</label>
													<cfinput name="Payment_Phone" type="text" value="#institution.getPayment_Phone()#" validate="telephone" message="Phone must be in ######-######-######## format" class="span12" placeholder="######-######-########" />
												</div>
											</div>
											<div class="span6">
												<div class="clearfix">
													<label for="Payment_Address1">Address 1</label>
													<cfinput type="text" name="Payment_Address1" value="#institution.getPayment_Address1()#" required="no" message="Address 1 is required" maxlength="200" class="span12" />
												</div>
												<div class="clearfix">
													<label for="Payment_Address2">Address 2</label>
													<cfinput type="text" name="Payment_Address2" value="#institution.getPayment_Address2()#" required="no" message="Address 2 is required" maxlength="200" class="span12" />
												</div>
												<div class="clearfix">
													<div class="row-fluid">
														<div class="span6">
															<label for="Payment_City">City</label>
															<cfinput type="text" name="Payment_City" value="#institution.getPayment_City()#" required="no" message="City is required" maxlength="100" class="span12">
														</div>
														<div class="span3">
															<label for="Payment_State">State</label>
															<cfselect name="Payment_State" query="states" display="Code" value="Code" selected="#institution.getPayment_State()#" queryPosition="below" class="span12">
																<option value="">Select...</option>
															</cfselect>
														</div>
														<div class="span3">
															<label for="Payment_Zip_Code">Zip Code</label>
															<cfinput type="text" name="Payment_Zip_Code" value="#institution.getPayment_Zip_Code()#" required="no" message="Zip Code is required and must be a valid zip code" validate="zipcode" maxlength="5" class="span12">
														</div>
													</div>
												</div>
											</div>
										</div>
									</div>
								</div>
							</div>
						</div>
					</div>
				</div>
				<div class="modal-footer">
					<a href="?view=#returnView#&#passbackQueryString#" class="btn btn-success">Cancel</a>
					<!--- <cfif IsUserInRole("Super User") OR IsUserInRole("Regional Admin")>
						<cfif institution.getInstitution_ID() gt 0 AND institution.getArchived() eq 0>
							<a class="btn btn-success" href="?action=archiveInstitution&view=#returnView#&Institution_ID=#institution.getInstitution_ID()#&#passbackQueryString#">Archive</a>
						<cfelseif institution.getInstitution_ID() gt 0 AND institution.getArchived() eq 1>
							<a class="btn btn-success" href="?action=unarchiveInstitution&view=#returnView#&Institution_ID=#institution.getInstitution_ID()#&#passbackQueryString#">Unarchive</a>
						</cfif>
					</cfif> --->
					<button type="submit" name="saveButton" class="btn btn-success">Save</button>
				</div>
			</div>

		</cfform>
	
	</cfoutput>
	
<cfelse>

	<div class="alert alert-info notFound">Institution not found</div>

</cfif>



